<template>
  <div style="height: 100%; width: 100%; position: relative">
      <div class="pagetop" style="text-align: left">
          <!-- <table style="width: 100%; border-collapse: collapse" class="QueryTable"> -->
          <table style="width: 100%; font-size: 12px;" border="0" class="QueryTable">
              <col style="width: 4%;" />
              <col style="width: 8%;" />
              <col style="width: 1%;" />
              <col style="width: 8%;" />
              <col style="width: 4%;" />
              <col style="width: 11%;" />
              <col style="width: 4%;" />
              <col style="width: 11%;" />
              <col style="width: 4%;" />
              <col style="width: 11%;" />
              <col style="width: 4%;" />
              <col style="width: 11%;" />
              <col style="width: 6%;" />
              <col style="width: 11%;" />
              <col style="width: 13%;" />
              <tr>
                  <td align="right" style="font-weight: bold;" :style="{'color':((datemonth=='1900-01-01 00:00:00'||datemonth==null)&&(dateweek=='1900-01-01 00:00:00'||dateweek==null))?'black':'lightgray'}">日期区间</td>
                  <td>
                      <el-date-picker v-model="datetime1" type="date" placeholder="开始日期" value-format="yyyy-MM-dd 00:00:00" size="mini" :clearable="false" style="width: 100%;min-width: 130px;" :disabled="((datemonth=='1900-01-01 00:00:00'||datemonth==null)&&(dateweek=='1900-01-01 00:00:00'||dateweek==null))?false:true"></el-date-picker>
                  </td>
                  <td>至</td>
                  <td>
                      <el-date-picker v-model="datetime2" type="date" placeholder="结束日期" value-format="yyyy-MM-dd 00:00:00" size="mini" :clearable="false" style="width: 100%;min-width: 130px;" :disabled="((datemonth=='1900-01-01 00:00:00'||datemonth==null)&&(dateweek=='1900-01-01 00:00:00'||dateweek==null))?false:true"></el-date-picker>
                  </td>
                  <td align="right" style="font-weight: bold;">质控仪器</td>
                  <td>
                      <rm-ddl-instrument @change="yq_change" width="140px;min-width: 110px;" v-model="instrid" defaultflag="1" prgno="LIS546" :clearable="true"></rm-ddl-instrument>
                  </td>
                  <td align="right" style="font-weight: bold;">水平</td>
                  <td>
                      <rm-ddl-common datatype="seccode" kindno="QCLEVEL" dataname="水平" v-model="level" width="100%;min-width: 110px;" @change="levelChange"></rm-ddl-common>
                  </td>
                  <td align="right" style="font-weight: bold;">批号</td>
                  <td>
                      <el-input v-model="batchno" style="width:100%;min-width:110px"></el-input>
                  </td>
                  <td align="right" style="font-weight: bold;">累计数据</td>
                  <td>
                      <el-select v-model="no_3sd" @change="sd3Change" style="width:100%;min-width: 110px;">
                          <el-option label="包含失控和非失控" value="0"></el-option>
                          <el-option label="不包含3SD" value="1"></el-option>
                          <el-option label="不包含失控" value="2"></el-option>
                      </el-select>
                  </td>
                  <td align="right" style="font-weight: bold;">CV合格依据</td>
                  <td>
                      <el-select v-model="cvjudge" style="width:100%;min-width: 110px;">
                          <el-option label="按原始CV(%)比较" value="0"></el-option>
                          <el-option label="按在控CV(%)比较" value="1"></el-option>
                          <el-option label="按累积CV(%)比较" value="2"></el-option>
                      </el-select>
                  </td>
              </tr>
              <tr>
                  <td align="right" :style="{'color':(datemonth=='1900-01-01 00:00:00'||datemonth==null)?'lightgray':'black'}" style="font-weight: bold;">月份</td>
                  <td>
                      <el-date-picker v-model="datemonth" type="month" placeholder="按月份统计" value-format="yyyy-MM-dd 00:00:00" size="mini" :clearable="true" style="width: 100%;min-width: 130px"></el-date-picker>
                  </td>
                  <td align="right" :style="{'color':(dateweek=='1900-01-01 00:00:00'||dateweek==null)?'lightgray':'black'}" style="font-weight: bold;">周</td>
                  <td>
                      <el-date-picker v-model="dateweek" type="week" placeholder="按星期统计" format="yyyy 第 WW 周" value-format="yyyy-MM-dd 00:00:00" size="mini" :clearable="true" :picker-options="{'firstDayOfWeek': 1}" style="width: 100%;min-width: 130px"></el-date-picker>
                  </td>
                  <td align="right" :style="{'color':'black'}" style="font-weight: bold;">仪器多选</td>
                  <td>
                      <rm-ddl-instrument :multiple_choice="true" :beforeChange="beforinstridChange" @change="instridlistchange" width="140px" v-model="instridlist" defaultflag="0" prgno="LIS546" :clearable="true"></rm-ddl-instrument>
                  </td>
                  <td colspan="12" style="text-align: left;">

                      <el-checkbox v-model="allbatchno" true-label="1" false-label="0">累计数据包含该批号所有数据</el-checkbox>
                      <el-checkbox v-model="controlstatus" true-label="1" false-label="0">区间非失控数据不包括未判定值</el-checkbox>
                      <el-checkbox v-model="inuseall" true-label="1" false-label="0">使用所有数据(包含非累计数据)</el-checkbox>
                      <el-checkbox v-model="showlastmonth">显示上月累计数据</el-checkbox>
                  </td>
              </tr>
              <tr>
                  <td colspan="15" align="right">
                      <el-button @click="QueryData()" v-has="'PINQUERY'" type="primary" icon="el-icon-search">查询</el-button>
                      <el-button @click="qcMonthShow(0)" icon="el-icon-edit">月度评价</el-button>
                      <el-button @click="btnExport()" icon="el-icon-upload2">导出</el-button>
                      <el-button icon="el-icon-view" @click="previewData">预览</el-button>
                      <el-button icon="el-icon-printer" @click="qcMonthShow(1)" v-has="'PPRINT'">打印</el-button>
                      <el-button icon="el-icon-edit-outline" @click="qcMonthShow(2)" v-has="'PPRINT'">样式设计</el-button>
                  </td>
              </tr>
          </table>
      </div>
      <div class="pagecenter">
          <vxe-table show-overflow ref="xTable" :loading="loading" height="auto" :data.sync="tableData" :cell-class-name="ColumnClassName" @current-Change="currentchangeEvent" border size="mini" header-align="center" align="center" highlight-current-row highlight-hover-row show-footer resizable stripe>
              <vxe-table-column field="labgroupname" title="检验组" width="120px" header-align="center" align="left"></vxe-table-column>
              <vxe-table-column field="instrna" title="检验仪器" width="100px" header-align="center" align="left" alignshow-header-overflow></vxe-table-column>
              <vxe-table-column field="itemcode" title="质控项目" width="120px" header-align="center" align="left"></vxe-table-column>
              <vxe-table-column field="itemcode_en" title="英文缩写" width="100px" header-align="center" align="left"></vxe-table-column>
              <vxe-table-column field="batchno" title="批号" width="70px"></vxe-table-column>
              <vxe-table-column field="qclevel" title="水平" width="50px"></vxe-table-column>
              <vxe-table-column field="itemcnt" title="测定数" width="60px"></vxe-table-column>
              <vxe-table-column field="outcontrolcnt" title="失控数" width="60px"></vxe-table-column>
              <vxe-table-column field="outcontrolrate" title="失控率%" width="60px"></vxe-table-column>
              <vxe-table-column field="handlecnt" title="处理率%" width="60px"></vxe-table-column>
              <vxe-table-column title="绘图基准数据">
                  <vxe-table-column field="val1" title="靶值" width="75px"></vxe-table-column>
                  <vxe-table-column field="sd1" title="基准SD" width="70px"></vxe-table-column>
                  <vxe-table-column field="cv1" title="基准CV(%)" width="65px"></vxe-table-column>
              </vxe-table-column>
              <vxe-table-column title="区间原始数据">
                  <vxe-table-column field="val2" title="原始均值" width="75px"></vxe-table-column>
                  <vxe-table-column field="sd2" title="原始SD" width="70px"></vxe-table-column>
                  <vxe-table-column field="cv2" title="原始CV(%)" width="65px"></vxe-table-column>
              </vxe-table-column>
              <vxe-table-column title="区间非失控数据">
                  <vxe-table-column field="val3" title="在控均值" width="75px"></vxe-table-column>
                  <vxe-table-column field="sd3" title="在控SD" width="70px"></vxe-table-column>
                  <vxe-table-column field="cv3" title="在控CV(%)" width="65px"></vxe-table-column>
              </vxe-table-column>
              <vxe-table-column :title="sd3title">
                  <vxe-table-column field="inusecnt" title="累计次数" width="70px" align="center"></vxe-table-column>
                  <vxe-table-column field="val4" title="累计均值" width="75px" align="center"></vxe-table-column>
                  <vxe-table-column field="sd4" title="累计SD" width="70px" align="center"></vxe-table-column>
                  <vxe-table-column field="cv4" title="累计CV(%)" width="65px" align="center"></vxe-table-column>
              </vxe-table-column>
              <vxe-table-column title="上月累计数据" v-if="showlastmonth">
                  <vxe-table-column field="inusecnt_last" title="上月累计次数" width="70px" align="center" show-header-overflow v-if="showlastmonth"></vxe-table-column>
                  <vxe-table-column field="val5" title="上月累计均值" width="75px" align="center" show-header-overflow v-if="showlastmonth"></vxe-table-column>
                  <vxe-table-column field="sd5" title="上月SD" width="70px" align="center" show-header-overflow v-if="showlastmonth"></vxe-table-column>
                  <vxe-table-column field="cv5" title="上月CV(%)" width="65px" align="center" show-header-overflow v-if="showlastmonth"></vxe-table-column>
              </vxe-table-column>
              <vxe-table-column v-if="qcshowmaxcv" field="maxcv" title="允许最大CV%" width="140px"></vxe-table-column>
              <vxe-table-column field="qcrule" title="质控规则" width="300px" header-align="center" align="left" alignshow-header-overflow></vxe-table-column>
              <vxe-table-column v-if="qcshowmaxcv" field="passflag" title="CV合格" width="120px"></vxe-table-column>
              <vxe-table-column field="qcname" title="质控品名称" width="160px"></vxe-table-column>
              <vxe-table-column v-show="false" field="qctea" title="tea" width="160px"></vxe-table-column>
              <vxe-table-column v-show="false" field="manufacturername" title="质控品生产厂家" width="160px"></vxe-table-column>
              <vxe-table-column v-show="false" field="vendonname" title="质控品供应商" width="160px"></vxe-table-column>
              <vxe-table-column v-show="false" field="reagentvendorname" title="质控品试剂厂商" width="160px"></vxe-table-column>
          </vxe-table>
      </div>
      <el-dialog width="700px" top="2px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="质控月评价" :visible.sync="qcMonthVisible">
          <table style="width: 100%">
              <tr>
                  <td style="text-align: right; width: 80px">质控月份：</td>
                  <td style="text-align: center; width: 100px">{{ this.com_qcMonth }}</td>
                  <td style="text-align: center; width: 80px">质控仪器：</td>
                  <td style="text-align: left; width: 640px">{{ this.instrName }}</td>
              </tr>
              <tr></tr>
              <tr></tr>
              <tr>
                  <td style="text-align: right;width:150px">
                      <span style="color: blue;">总结意见：</span>
                  </td>
                  <td colspan="3">
                      <el-input v-model="summary" type="textarea" :rows="6" show-word-limit></el-input>
                  </td>
              </tr>
              <tr>
                  <td style="text-align: right">
                      <span style="color: blue">总结人：</span>
                  </td>
                  <td>
                      <el-input v-model="summary_userna" style="width:150px" :disabled="true"></el-input>
                  </td>
                  <td style="text-align: right;width:200px">
                      <span style="color: blue;">总结时间：</span>
                  </td>
                  <td>
                      <el-input v-model="summary_dt" style="width:150px" :disabled="true"></el-input>
                  </td>
              </tr>
              <tr>
                  <td style="text-align: right">
                      <span style="color: blue">主管意见：</span>
                  </td>
                  <td colspan="3">
                      <el-input v-model="manager_note" type="textarea" :rows="6" show-word-limit></el-input>
                  </td>
              </tr>
              <tr>
                  <td style="text-align: right">
                      <span style="color: blue">主管：</span>
                  </td>
                  <td>
                      <el-input v-model="managerna" style="width:150px" :disabled="true"></el-input>
                  </td>
                  <td style="text-align: right;width:200px">
                      <span style="color: blue;">签字时间：</span>
                  </td>
                  <td>
                      <el-input v-model="manager_dt" style="width:150px" :disabled="true"></el-input>
                  </td>
              </tr>
          </table>
          <span slot="footer" class="dialog-footer">
              <!-- <el-button style="margin: 0px 10px 0px 5px" @click="qcMonthSave()">确定</el-button> -->
              <el-button style="margin: 0px 10px 0px 5px" icon="el-icon-edit" @click="qcMonthSave(1)">总结审核</el-button>
              <el-button v-has="'PVERIFY'" style="margin: 0px 10px 0px 5px" icon="el-icon-check" @click="qcMonthSave(2)">主管签字</el-button>
              <el-button v-has="'PVERIFY'" style="margin: 0px 10px 0px 5px" icon="el-icon-refresh-left" @click="qcMonthSave(3)">取消签字</el-button>
              <el-button style="margin: 0px 10px 0px 5px" @click="(qcMonthVisible = false), (qcMonthSummaryData = {})">取消</el-button>
          </span>
      </el-dialog>
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :visible.sync="bShowOutReport" title="失控报告预览" :destroy-on-close="true" top="5vh" width="710px">
          <div style="height:700px;width:700px;border:1px solid #CCC;" v-loading="rightloading" element-loading-text="数据加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)">
              <!--   <pdf v-for="i in pdfPages" :key="i" :src="url" :page="i"></pdf> -->
              <embed :src="htmlstr" type="application/pdf" width="100%" height="99%" :key="htmlstrkey">
          </div>
      </el-dialog>
  </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils"; //引入工具类
// import Moment from "moment";
export default {
  name: "LIS546",
  data() {
      return {
          instrid: "", //仪器ID
          instridlist: "", //仪器多选
          instrName: "",
          level: "", //水平
          levelname: "",
          batchno: "", //批号
          no_3sd: "0", //累计数据
          cvjudge: "0", //CV合格比较
          allbatchno: "0", //累计数据包含该批号所有数据
          controlstatus: "0", //区间非失控数据不包括未判定值
          inuseall: "0", //使用所有数据(包含非累计数据)
          showlastmonth: false, //显示上月累计数据
          datetime1: "", //起始日期
          datetime2: "", //结束日期
          datemonth: "", //质控月份
          dateweek: "", 
          tableData: [],
          tableColumns: [],
          sd3title: "累计数据(包含失控和非失控)",
          loading: false,
          qcMonthVisible: false,
          qcMonthSummaryData: {}, //质控月度总结
          summary: "",
          manager_note: "",
          summary_user: "",
          summary_userna: "",
          summary_dt: "",
          managerna: "",
          managerna: "",
          manager_dt: "",
          printstyle: "",
          printinfo: {},
          qcshowmaxcv: true,
          passcnt: 0,
          notpasscnt: 0,
          notpassrptcnt: 0,
          passrptcnt: 0,
          instrsname: "",
          exportTableColLen: 0,
          //预览
          bShowOutReport: false,
          htmlstr: "",
          htmlstrkey: 0,
          rightloading: false,
      };
  },
  computed: {
      com_qcMonth: function () {
          if ((this.datemonth == "1900-01-01 00:00:00" || this.datemonth == null) && (this.dateweek == "1900-01-01 00:00:00" || this.dateweek == null)) {
              //日期区间 取首日所属月份
              let month = XEUtils.clone(this.datetime1, true);
              return XEUtils.toDateString(month, "yyyyMM");
          } else {
              if (this.datemonth == "1900-01-01 00:00:00" || this.datemonth == null) {
                  //按周统计 取周一所属月
                  let month = XEUtils.getWhatDay(this.dateweek, -1);
                  return XEUtils.toDateString(month, "yyyyMM");
              } else if (this.dateweek == "1900-01-01 00:00:00" || this.dateweek == null) {
                  //按月统计
                  let month = XEUtils.clone(this.datemonth, true);
                  return XEUtils.toDateString(month, "yyyyMM");
              }
          }
      },
  },
  watch: {
      dateweek: function () {
          if (this.dateweek != null) {
              this.datemonth = null;
          }
      },
      datemonth: function () {
          if (this.datemonth != null) {
              this.dateweek = null;
          }
      },
  },
  created() {
      this.InitPageDate(); //初始化主列表
      this.getinitb(); //获取打印id
  },
  mounted() {},
  updated() {},
  methods: {
      //预览
      previewData(StatColName, StatData) {
           let printdata = this.$refs.xTable.afterFullData;
          if (printdata.length == 0) {
              var statweek = "";
              var statmonth = "";
              if (this.dateweek != null) {
                  statweek = XEUtils.getYearWeek(this.dateweek);
              } else if (this.datemonth != null) {
                  statmonth = this.datemonth;
              }
              this.$message.error("错误：没有要预览的数据！");
          } else {
              if (printdata.length > 0 && this.printinfo != {}) {
                  printdata[0].psummary = this.printinfo.summary;
                  printdata[0].pmanager_note = this.printinfo.manager_note;
                  printdata[0].psummary_userna = this.printinfo.summary_userna;
                  printdata[0].psummary_dt = this.printinfo.summary_dt;
                  printdata[0].pmanagerna = this.printinfo.managerna;
                  printdata[0].pmanager_dt = this.printinfo.manager_dt;
                  printdata[0].pstartdt = this.datetime1;
                  printdata[0].penddt = this.datetime2;
                  printdata[0].pstatweek = statweek;
                  printdata[0].pstatmonth = statmonth;
                  printdata[0].passcnt = this.passcnt;
                  printdata[0].notpasscnt = this.notpasscnt;
                  printdata[0].notpassrptcnt = this.notpassrptcnt;
                  printdata[0].passrptcnt = this.passrptcnt;
                  printdata[printdata.length - 1].psummary = this.printinfo.summary;
                  printdata[printdata.length - 1].pmanager_note = this.printinfo.manager_note;
                  printdata[printdata.length - 1].psummary_userna = this.printinfo.summary_userna;
                  printdata[printdata.length - 1].psummary_dt = this.printinfo.summary_dt;
                  printdata[printdata.length - 1].pmanagerna = this.printinfo.managerna;
                  printdata[printdata.length - 1].pmanager_dt = this.printinfo.manager_dt;
                  printdata[printdata.length - 1].pstartdt = this.datetime1;
                  printdata[printdata.length - 1].penddt = this.datetime2;
                  printdata[printdata.length - 1].pstatweek = statweek;
                  printdata[printdata.length - 1].pstatmonth = statmonth;
                  printdata[printdata.length - 1].passcnt = this.passcnt;
                  printdata[printdata.length - 1].notpasscnt = this.notpasscnt;
                  printdata[printdata.length - 1].notpassrptcnt = this.notpassrptcnt;
                  printdata[printdata.length - 1].passrptcnt = this.passrptcnt;
              }
              let columns = this.$refs.xTable.getTableColumn().tableColumn;
              if (printdata.length > 0) {
                  columns.push({ title: "tea", property: "manufacturername" });
                  columns.push({ title: "质控品生产厂家", property: "manufacturername" });
                  columns.push({ title: "质控品供应商", property: "vendonname" });
                  columns.push({ title: "质控品试剂厂商", property: "reagentvendorname" });
                  columns.push({ title: "总结", property: "psummary" });
                  columns.push({ title: "主管意见", property: "pmanager_note" });
                  columns.push({ title: "总结人", property: "psummary_userna" });
                  columns.push({ title: "总结时间", property: "psummary_dt" });
                  columns.push({ title: "主管", property: "pmanagerna" });
                  columns.push({ title: "签字时间", property: "pmanager_dt" });
                  columns.push({ title: "起始日期", property: "pstartdt" });
                  columns.push({ title: "结束日期", property: "penddt" });
                  columns.push({ title: "周", property: "pstatweek" });
                  columns.push({ title: "月份", property: "pstatmonth" });
                  columns.push({ title: "合格数", property: "passcnt" });
                  columns.push({ title: "不合格数", property: "notpasscnt" });
                  columns.push({ title: "项目合格数", property: "passrptcnt" });
                  columns.push({ title: "项目不合格数", property: "notpassrptcnt" });
              }
              let str = JSON.stringify(this.$pub.InitColumn(columns));
              str += "\r";
              str += JSON.stringify(printdata);
              this.bShowOutReport = true;
              let sql = btoa(encodeURIComponent(str));
              this.$tool
                  .request({
                      url: "ucent/print",
                      method: "post",
                      data: {
                          action: "previewpdf",
                          styleid: this.printstyle,
                          sql: str,
                          tablename: "off_devmaint",
                      },
                  })
                  .then((res) => {
                      if (res.flag == "0") {
                          this.$alert(res.msg, "提示");
                      } else {
                          this.htmlstr = res.pdfurl + "#toolbar=0";
                          this.htmlstrkey++;
                      }
                      this.rightloading = false;
                  })
                  .catch((e) => {
                      this.$alert("预览报告出错！", "错误", {
                          confirmButtonText: "确定",
                      });
                      this.rightloading = false;
                  });
          } 
      },
      beforinstridChange(instridlist, flag) {
          // if (flag) {
          this.instridlist = XEUtils.clone(instridlist, true);
          // }
          return true;
      },
      instridlistchange(code, name) {
          this.instridlist = code;
          this.instrsname = name;
          if (this.instrid != "") this.instrid = "";
          // this.rptunitname = name;
          // this.dialogTableVisible = false;
          if (this.multiple_choice) {
              //!
              this.$refs.rptunitInput.focus();
          }
      },
      getinitb() {
          this.$tool
              .request({
                  url: "LIS/LIS5/LIS546",
                  method: "post",
                  data: {
                      action: "InitOptions",
                  },
              })
              .then((res) => {
                  this.printstyle = res.printstyle;
                  this.qcshowmaxcv = res.qcshowmaxcv == "0" ? false : true;
              });
      },
      printrecord() {
          let printdata = this.$refs.xTable.afterFullData;
          if (printdata.length == 0) {
              var statweek = "";
              var statmonth = "";
              if (this.dateweek != null) {
                  statweek = XEUtils.getYearWeek(this.dateweek);
              } else if (this.datemonth != null) {
                  statmonth = this.datemonth;
              }
              this.$message.error("错误：没有要打印的数据！");
          } else {
              if (printdata.length > 0 && this.printinfo != {}) {
                  printdata[0].psummary = this.printinfo.summary;
                  printdata[0].pmanager_note = this.printinfo.manager_note;
                  printdata[0].psummary_userna = this.printinfo.summary_userna;
                  printdata[0].psummary_dt = this.printinfo.summary_dt;
                  printdata[0].pmanagerna = this.printinfo.managerna;
                  printdata[0].pmanager_dt = this.printinfo.manager_dt;
                  printdata[0].pstartdt = this.datetime1;
                  printdata[0].penddt = this.datetime2;
                  printdata[0].pstatweek = statweek;
                  printdata[0].pstatmonth = statmonth;
                  printdata[0].passcnt = this.passcnt;
                  printdata[0].notpasscnt = this.notpasscnt;
                  printdata[0].notpassrptcnt = this.notpassrptcnt;
                  printdata[0].passrptcnt = this.passrptcnt;
                  printdata[printdata.length - 1].psummary = this.printinfo.summary;
                  printdata[printdata.length - 1].pmanager_note = this.printinfo.manager_note;
                  printdata[printdata.length - 1].psummary_userna = this.printinfo.summary_userna;
                  printdata[printdata.length - 1].psummary_dt = this.printinfo.summary_dt;
                  printdata[printdata.length - 1].pmanagerna = this.printinfo.managerna;
                  printdata[printdata.length - 1].pmanager_dt = this.printinfo.manager_dt;
                  printdata[printdata.length - 1].pstartdt = this.datetime1;
                  printdata[printdata.length - 1].penddt = this.datetime2;
                  printdata[printdata.length - 1].pstatweek = statweek;
                  printdata[printdata.length - 1].pstatmonth = statmonth;
                  printdata[printdata.length - 1].passcnt = this.passcnt;
                  printdata[printdata.length - 1].notpasscnt = this.notpasscnt;
                  printdata[printdata.length - 1].notpassrptcnt = this.notpassrptcnt;
                  printdata[printdata.length - 1].passrptcnt = this.passrptcnt;
              }
              let columns = this.$refs.xTable.getTableColumn().tableColumn;
              if (printdata.length > 0) {
                  const rload = this.$pub.openLoading(this, "正在打开报表设计器，请稍候……");
                  columns.push({ title: "tea", property: "manufacturername" });
                  columns.push({ title: "质控品生产厂家", property: "manufacturername" });
                  columns.push({ title: "质控品供应商", property: "vendonname" });
                  columns.push({ title: "质控品试剂厂商", property: "reagentvendorname" });
                  columns.push({ title: "总结", property: "psummary" });
                  columns.push({ title: "主管意见", property: "pmanager_note" });
                  columns.push({ title: "总结人", property: "psummary_userna" });
                  columns.push({ title: "总结时间", property: "psummary_dt" });
                  columns.push({ title: "主管", property: "pmanagerna" });
                  columns.push({ title: "签字时间", property: "pmanager_dt" });
                  columns.push({ title: "起始日期", property: "pstartdt" });
                  columns.push({ title: "结束日期", property: "penddt" });
                  columns.push({ title: "周", property: "pstatweek" });
                  columns.push({ title: "月份", property: "pstatmonth" });
                  columns.push({ title: "合格数", property: "passcnt" });
                  columns.push({ title: "不合格数", property: "notpasscnt" });
                  columns.push({ title: "项目合格数", property: "passrptcnt" });
                  columns.push({ title: "项目不合格数", property: "notpassrptcnt" });
              }
              let str = JSON.stringify(this.$pub.InitColumn(columns));
              str += "\r";
              str += JSON.stringify(printdata);
              let sql = btoa(encodeURIComponent(str));
              jsObj.PrintCustomJsonReport(this.printstyle, sql, "admin", "质控月统计报表", "");
          }
      },
      RptStyleSetting() {
          var user = this.$tool.getSession(this.$tool.loginuserno);
          if (user != "admin") {
              this.$message.error("如需调整样式请联系管理员。");
          } else {
              var data = this.$refs.xTable.tableData;
              var statweek = "";
              var statmonth = "";
              if (this.dateweek != null) {
                  statweek = XEUtils.getYearWeek(this.dateweek);
              } else if (this.datemonth != null) {
                  statmonth = this.datemonth.substring(6);
              }
              if (data.length > 0 && this.printinfo != {}) {
                  data[0].psummary = this.printinfo.summary;
                  data[0].pmanager_note = this.printinfo.manager_note;
                  data[0].psummary_userna = this.printinfo.summary_userna;
                  data[0].psummary_dt = this.printinfo.summary_dt;
                  data[0].pmanagerna = this.printinfo.managerna;
                  data[0].pmanager_dt = this.printinfo.manager_dt;
                  data[0].pstartdt = this.datetime1;
                  data[0].penddt = this.datetime2;
                  data[0].pstatweek = statweek;
                  data[0].pstatmonth = statmonth;
                  data[0].passcnt = this.passcnt;
                  data[0].notpasscnt = this.notpasscnt;
                  data[0].notpassrptcnt = this.notpassrptcnt;
                  data[0].passrptcnt = this.passrptcnt;
                  data[data.length - 1].psummary = this.printinfo.summary;
                  data[data.length - 1].pmanager_note = this.printinfo.manager_note;
                  data[data.length - 1].psummary_userna = this.printinfo.summary_userna;
                  data[data.length - 1].psummary_dt = this.printinfo.summary_dt;
                  data[data.length - 1].pmanagerna = this.printinfo.managerna;
                  data[data.length - 1].pmanager_dt = this.printinfo.manager_dt;
                  data[data.length - 1].pstartdt = this.datetime1;
                  data[data.length - 1].penddt = this.datetime2;
                  data[data.length - 1].pstatweek = statweek;
                  data[data.length - 1].pstatmonth = statmonth;
                  data[data.length - 1].passcnt = this.passcnt;
                  data[data.length - 1].notpasscnt = this.notpasscnt;
                  data[data.length - 1].notpassrptcnt = this.notpassrptcnt;
                  data[data.length - 1].passrptcnt = this.passrptcnt;
              }
              if (data.length > 0) {
                  const rload = this.$pub.openLoading(this, "正在打开报表设计器，请稍候……");
                  let columns = this.$refs.xTable.getTableColumn().tableColumn;
                  columns.push({ title: "tea", property: "manufacturername" });
                  columns.push({ title: "质控品生产厂家", property: "manufacturername" });
                  columns.push({ title: "质控品供应商", property: "vendonname" });
                  columns.push({ title: "质控品试剂厂商", property: "reagentvendorname" });
                  columns.push({ title: "总结", property: "psummary" });
                  columns.push({ title: "主管意见", property: "pmanager_note" });
                  columns.push({ title: "总结人", property: "psummary_userna" });
                  columns.push({ title: "总结时间", property: "psummary_dt" });
                  columns.push({ title: "主管", property: "pmanagerna" });
                  columns.push({ title: "签字时间", property: "pmanager_dt" });
                  columns.push({ title: "起始日期", property: "pstartdt" });
                  columns.push({ title: "结束日期", property: "penddt" });
                  columns.push({ title: "周", property: "pstatweek" });
                  columns.push({ title: "月份", property: "pstatmonth" });
                  columns.push({ title: "合格数", property: "passcnt" });
                  columns.push({ title: "不合格数", property: "notpasscnt" });
                  columns.push({ title: "项目合格数", property: "passrptcnt" });
                  columns.push({ title: "项目不合格数", property: "notpassrptcnt" });
                  let str = JSON.stringify(this.$pub.InitColumn(columns));
                  str += "\r";
                  str += JSON.stringify(data);
                  let sql = btoa(encodeURIComponent(str));
                  jsObj.SetCustomJsonPrintConfig(this.printstyle, sql, "admin", "质控月统计报表");
                  rload.close();
              } else {
                  this.$message.error("错误：没有要打印的数据！");
              }
          }
      },
      //切换仪器时
      yq_change(id, name) {
          this.instrid = id;
          this.instrName = name;
      },
      levelChange(code, name) {
          this.level = code;
          this.levelname = name;
      },
      //页面初始化加载
      InitPageDate() {
          var date = new Date();
          this.datetime1 = XEUtils.toDateString(date, "yyyy-MM-01 00:00:00"); //起 始结束日期
          this.datetime2 = XEUtils.toDateString(date, "yyyy-MM-dd 00:00:00");
          this.datemonth = XEUtils.toDateString(new Date(), "yyyy-01-01 00:00:00");
      },
      //表格方法
      currentchangeEvent({ row, column }) {},
      //后台交互方法
      QueryData() {
          var searchParam = {
              level: this.level,
              qcdate1: this.datetime1,
              qcdate2: this.datetime2,
              instrid: this.instrid,
              instridlist: this.instrid ? "" : this.instridlist,
              inuseall: this.inuseall,
              showlastmonth: this.showlastmonth ? "1" : "0",
              allbatchno: this.allbatchno,
              controlstatus: this.controlstatus,
              batchno: this.batchno,
              no_3sd: this.no_3sd,
              datemonth: this.datemonth ? this.datemonth : "",
              dateweek: this.dateweek ? this.dateweek : "",
              cvjudge: this.cvjudge,
          };
          // if (!this.instrid) {
          //     this.$alert("没有选择仪器，无法查询!", "提示");
          //     return;
          // }
          this.passcnt = 0;
          this.notpasscnt = 0;
          this.notpassrptcnt = 0;
          this.passrptcnt = 0;
          this.loading = true;
          this.$tool
              .request({
                  url: "LIS/LIS5/LIS546",
                  method: "post",
                  timeout: 3000000,
                  data: {
                      action: "query",
                      ...searchParam,
                  },
              })
              .then((res) => {
                  console.log("🐮🍺Kanpai~res", res);
                  if (res.errcode == "1") {
                      for (let i = 0; i < res.Data.length; i++) {
                          for (var item in res.Data[i]) {
                              if (item.indexOf("val") > -1 || item.indexOf("sd") > -1 || item.indexOf("cv") > -1) res.Data[i][item] = XEUtils.toFixedString(res.Data[i][item] - 0, 2);
                          }
                          res.Data[i].outcontrolrate = XEUtils.toFixedString(((res.Data[i].outcontrolcnt - 0) * 100) / (res.Data[i].itemcnt - 0), 2);
                      }
                      this.tableData = res.Data;
                      if (res.Data.length > 0) this.$refs.xTable.setCurrentRow(this.tableData[0]);
                      this.passcnt = res.passcnt;
                      this.notpasscnt = res.notpasscnt;
                      this.notpassrptcnt = res.notpassrptcnt;
                      this.passrptcnt = res.passrptcnt;
                  }
                  this.loading = false;
              })
              .catch(() => {
                  this.loading = false;
              });
      },
      //单元格样式
      ColumnClassName({ row, column }) {
          if (column.property.indexOf("cv") > -1) {
              if (row[column.property] - 0 > row.maxcv - 0) {
                  return "highCV";
              }
          } else if (column.property.indexOf("sd") > -1) {
              return "sdBack";
          }
      },
      //累计数据改变事件
      sd3Change(val) {
          switch (val) {
              case "0":
                  this.sd3title = "累计数据(包含失控和非失控)";
                  break;
              case "1":
                  this.sd3title = "累计数据(不包含3SD)";
                  break;
              case "2":
                  this.sd3title = "累计数据(不包含失控)";
                  break;
              default:
                  this.sd3title = "累计数据";
                  break;
          }
      },
      //导出
      btnExport() {
          let data = this.getExportData();
          let filtertxt = this.getExportFilter();
          this.$pub.exportTableExcelWithData(data, this.exportTableColLen, "质控CV统计.xlsx", filtertxt, "统计查询：");
      },
      // 获取当前导出文件的所有查询条件
      getExportFilter() {
          let filtertxt = "日期区间:" + XEUtils.toDateString(this.datetime1, "yyyy-MM-dd") + "至" + XEUtils.toDateString(this.datetime2, "yyyy-MM-dd") + "; ";
          if (this.instrid) filtertxt += "质控仪器:" + this.instrName + "; ";
          if (this.level) filtertxt += "水平:" + this.levelname + "; ";
          if (this.batchno) filtertxt += "批号:" + this.batchno + "; ";
          if (this.no_3sd) filtertxt += this.sd3title + "; ";
          if (this.datemonth) filtertxt += "月份:" + XEUtils.toDateString(this.datemonth, "yyyy-MM") + "; ";
          if (this.dateweek) filtertxt += "周:" + XEUtils.toDateString(this.dateweek, "yyyy 第 WW 周") + "; ";
          if (this.instridlist) filtertxt += "仪器多选:" + this.instrsname + "; ";
          if (this.allbatchno == "1") filtertxt += "累计数据包含该批号所有数据; ";
          if (this.controlstatus == "1") filtertxt += "区间非失控数据不包括未判定值; ";
          if (this.inuseall == "1") filtertxt += "使用所有数据(包含非累计数据); ";
          if (this.showlastmonth) filtertxt += "显示上月累计数据; ";
          return filtertxt;
      },
      getExportData() {
          var allcolumns = this.$refs.xTable.getColumns();
          var tableColumn = [];
          for (let i = 0; i < allcolumns.length; i++) {
              tableColumn.push({ field: allcolumns[i].property, title: allcolumns[i].title });
          }
          let datas = this.tableData;
          this.exporPrintTabletTableColLen = tableColumn.length;
          let columns = tableColumn.filter((item) => item.field);
          let headers = [columns.map((item) => item.title)];
          return headers.concat(
              datas.map((row) => {
                  return columns.map((column) => {
                      return row[column.field];
                  });
              })
          );
      },
      toBuffer(wbout) {
          let buf = new ArrayBuffer(wbout.length);
          let view = new Uint8Array(buf);
          for (let index = 0; index !== wbout.length; ++index) view[index] = wbout.charCodeAt(index) & 0xff;
          return buf;
      },
      //打印
      PrintTable() {
          if (typeof jsObj != "undefined") {
              //this.$pub.printCustomXml(this.Printstr,'6010','admin','LIS546');
              this.$pub.designCustomXml(this.Printstr, "6010", "admin", "LIS546");
          } else {
              this.$alert("请使用" + this.$pub.clientname + "打开系统", "错误", {
                  confirmButtonText: "确定",
              });
          }
      },
      //月度评价
      qcMonthShow(flag) {
          if (!(this.instrid > 0)) {
              this.$alert("月度评价只支持单仪器模式。", {
                  confirmButtonText: "确定",
              });
              return false;
          }
          this.qcMonthSummaryData = {};
          this.qcMonthSummaryData.qcmonth = this.com_qcMonth;
          this.qcMonthSummaryData.instrid = this.instrid;
          if (flag > 0) {
              this.printinfo = {};
          } else {
              this.qcMonthVisible = true;
              this.summary = "";
              this.manager_note = "";
              this.summary_userna = "";
              this.summary_dt = "";
              this.managerna = "";
              this.manager_dt = "";
          }
          this.$tool
              .request({
                  url: "LIS/LIS5/LIS546",
                  method: "post",
                  data: {
                      action: "qcMonthShow",
                      ...this.qcMonthSummaryData,
                  },
              })
              .then((res) => {
                  if (res.errcode == "1") {
                      var data = res.Data;
                      if (data.length > 0) {
                          if (flag > 0) {
                              this.printinfo = data[0];
                          } else {
                              this.summary = data[0].summary;
                              this.summary_userna = data[0].summary_userna;
                              this.manager_note = data[0].manager_note;
                              this.summary_dt = data[0].summary_dt;
                              this.managerna = data[0].managerna;
                              this.manager_dt = data[0].manager_dt;
                          }
                      }
                  } else {
                      // this.$alert(res.errmsg, "错误");
                  }
                  if (flag == 1) this.printrecord();
                  else if (flag == 2) this.RptStyleSetting();
              })
              .catch((error) => {
                  //this.$alert(error, "错误");
              });
      },
      // 月度评价保存
      qcMonthSave(flag) {
          if (flag == 1 && !(this.managerna == "" || this.managerna == null)) {
              this.$message.warning("修改总结意见失败：主管已签字。");
              return;
          }
          this.qcMonthSummaryData = {};
          this.qcMonthSummaryData.qcmonth = this.com_qcMonth;
          this.qcMonthSummaryData.instrid = this.instrid;
          this.qcMonthSummaryData.summary = this.summary;
          this.qcMonthSummaryData.manager_note = this.manager_note;
          this.qcMonthSummaryData.summary_userna = this.summary_userna;
          this.qcMonthSummaryData.summary_dt = this.summary_dt;
          this.qcMonthSummaryData.managerna = this.managerna;
          this.qcMonthSummaryData.manager_dt = this.manager_dt;
          this.$tool
              .request({
                  url: "LIS/LIS5/LIS546",
                  method: "post",
                  data: {
                      action: "qcMonthSave",
                      flag: flag,
                      ...this.qcMonthSummaryData,
                  },
              })
              .then((res) => {
                  if (res.errcode == "1") {
                      this.$message({
                          message: "修改成功！",
                          type: "success",
                      });
                      this.qcMonthVisible = false;
                  } else {
                      this.$alert(res.errmsg, "错误");
                  }
              })
              .catch((error) => {
                  this.$alert(error, "错误");
              });
      },
  },
};
</script>


<style scoped>
::v-deep .highCV {
  color: red;
}
::v-deep .sdBack {
  background-color: #f2f2f2;
}
.pagetop {
  width: 100%;
  height: 90px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
}
.pagecenter {
  position: absolute;
  top: 94px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}
.middle-right {
  position: absolute;
  height: 100%;
  right: 0px;
  bottom: 0px;
  overflow: visible;
}
.middle-center {
  position: absolute;
  height: 100%;
  overflow: auto;
}

.QueryTable tr td:nth-child(even) {
  /* text-align: right;
  white-space: nowrap;
  font-size: 12px;
  width: 70px; */
  font-weight: bold;
  /* padding-right: 5px; */
}
/* 剔除日期框多余右边距 */
::v-deep.el-input--suffix .el-input__inner {
  padding-right: 0px;
}
::v-deep.el-input.is-disabled .el-input__inner {
  color: #000000;
}
</style>